package prefixSumStudy;

public class MaxSubArray {

    public static void main(String[] args) {

    }

    public int maxSubArray(int[] nums){
        int preSum = 0;
        int curSum = 0;
        int maxSum = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++){
            curSum += nums[i];
            maxSum = Math.max(maxSum, curSum - preSum);
            preSum = Math.min(preSum, curSum);
        }
        return maxSum;
    }
}
